<template>
	<div>
		<div class="client" style="background-color: #fff;">
			<u-field label-width="150" label="客户编码：" v-model="entity.cCusCode" disabled>
			</u-field>
			<u-field label-width="150" label="客户名称：" v-model="entity.cCusName" disabled>
			</u-field>
			<u-field label-width="150" label="单据日期: " v-model="entity.dDate" disabled>
			</u-field>
			<u-field label-width="150" rows="1" autosize type="textarea" label="收货地址: " v-model="entity.cCusOAddress"
				disabled>
			</u-field>
		</div>

		<view>
			<u-tabs :list="tabsList" :is-scroll="true" :current="current" @change="tablechange" font-size="28"></u-tabs>
		</view>
		<view class="formalBox">
			<!-- @scrolltolower="getNewsData()" :style="{height:scrollviewHeight}" -->
			<scroll-view style="width: 100%;height: 100%;" scroll-y="true" @scrolltolower="lower">
				<view>
					<view>
						<div class="boxFormal" v-for="item in data" :key="item.Id">
							<div class="companyName" style="font-size: 14px;" v-if="current==0">产品名称:{{ item.cInvName }}
							</div>
							<div class="companyName" style="font-size: 14px;"
								v-if="current==1  || current==2 || current==3">
								产品名称:{{ item.cinvname }}</div>

							<div v-if="current==0" class="rightFlax">
								<div class="font20">订单号: {{ item.cSOCode }}</div>
								<div class="font20">编码: {{ item.cInvCode }}</div>
							</div>
							<div v-if="current==1 || current==2 " class="rightFlax">
								<div v-if="current==1" class="font20">单号: {{ item.cdlcode }}</div>
								<div v-if="current==2" class="font20">单号: {{ item.ccode }}</div>
								<div v-if="current==3" class="font20">单号: {{ item.csbvcode }}</div>
								<div class="font20">日期: {{ $moment(item.ddate).format("YYYY-MM-DD") }}</div>
							</div>
							<div class="code">
								<div v-if="current==0" style="padding-right: 30px" class="font20">
									数量:{{ item.iQuantity }}
								</div>
								<div v-if="current==1" style="padding-right: 30px" class="font20">
									发货金额(元): {{ $utils.momenyFormat(item.isum) }}
								</div>
								<div v-if="current==3" style="padding-right: 30px" class="font20">
									金额(元): {{ $utils.momenyFormat(item.isum) }}
								</div>
								<div v-if="current==2" style="padding-right: 30px" class="font20">
									批号: {{ item.cbatch }}
								</div>
								<div v-if="current==0" class="font20">
									单价(元): {{
				            $utils.momenyFormat(item.iTaxUnitPrice) 
				              
				          }}
								</div>
								<div v-if="current==1" class="font20">
									发货数量: {{
								  parseInt(item.iquantity)  
								  }}
								</div>
								<div v-if="current==2" class="font20">
									出库数量: {{
								  parseInt(item.iquantity)  
								  }}
								</div>
								<div v-if="current==3" class="font20">
									数量: {{
								  parseInt(item.iquantity)  
								  }}
								</div>
							</div>
						</div>
					</view>
				</view>
				<div style="padding-bottom: 20px;">
					<LoadingMore :status="status" :contentText="contentText" :rows="data"></LoadingMore>
				</div>
			</scroll-view>
		</view>

	</div>
</template>

<script>
	import {
		SO_SOMainGetTheData,
		SO_SODetailsGetDataList,
		SO_SOMainGetSa_SaleOrderAscendDis,
		SO_SOMainGetSa_SaleOrderAscendOut,
		SO_SOMainGetSa_SaleOrderAscendBill,
		SO_SOMainGetSA_ProcessGathering
	} from '@/api/interface.js'

	export default {
		components: {},
		data() {
			return {
				data: [],
				// 加载状态
				status: "loading",
				contentText: {
					contentdown: '轻轻上拉',
					contentrefresh: '努力加载中...',
					contentnomore: '实在没有了'
				},
				// 顶部导航栏切换
				tabsList: [{
						name: '订单信息'
					}, {
						name: '发货信息'
					}, {
						name: '出库信息',
					},
					{
						name: '发票信息',
					},
					{
						name: '收款信息',
					}
				],
				pagination: {
					current: 1,
					pageSize: 10,
				},
				Total: 0,
				current: 0,
				entity: {},
				show: false,
				showDate: false,
				Id: ""
			};
		},
		onLoad(options) {
			// 初始化加载订单信息tab
			this.loading0 = true;
			// 初始化没有加载完成订单信息tab
			this.finished0 = false;
			var obj = {
				ID: options.Id
			};

			this.openForm(obj);
		},
		//下拉刷新
		onPullDownRefresh() {
			this.pagination.current = 1
			uni.stopPullDownRefresh();
			this.data = [];
			this.getTableData(this.active)
		},
		methods: {
			// onLoad() {
			// 	this["PageRows" + this.active] += 20;
			// 	this.getTableData(this.active);
			// },
			// 触底
			lower(e) {
				if (this.data.length >= this.Total) return
				this.pagination.current++;
				this.getTableData(this.active)
			},
			// 导航栏切换点击
			tablechange(key) {
				this.active = key;
				this.current = key
				this.data = []
				this.status = "loading"
				this.getTableData(key);
			},

			getTableData(key) {
				// this.status = "loading"
				let Search = [{
					Condition: "cSOCode",
					Keyword: this.entity.cSOCode
				}]
				if (key == 0) {
					SO_SODetailsGetDataList({
							PageIndex: this.pagination.current,
							PageRows: this.pagination.pageSize,
							Search: [{
								Condition: "cSOCode",
								Keyword: this.entity.cSOCode
							}],
							SortField: "ID",
							SortType: "desc"
						})
						.then(resJson => {
							if (resJson.Success) {
								this.Total = resJson.Total;
								if (this.pagination.current == 1) {
									this.data = resJson.Data;
								} else {
									this.data = this.data.concat(resJson.Data);
								}
								if (this.data.length >= resJson.Total) {
									this.status = 'noMore'; // 没有更多数据
								} else {
									this.status = 'loading'; // 没有更多数据
								}
							} else {
								this.$errorToast(resJson.Msg);
								this.status = 'noMore'; // 没有更多数据
							}
						});
				} else if (key == 1) {
					SO_SOMainGetSa_SaleOrderAscendDis({
							PageIndex: this.pagination.current,
							PageRows: this.pagination.pageSize,
							Search: Search
						})
						.then(resJson => {
							if (resJson.Success) {
								this.Total = resJson.Total;
								this.data = resJson.Data;
								if (this.pagination.current == 1) {
									this.data = resJson.Data;
								} else {
									this.data = this.data.concat(resJson.Data);
								}
								if (this.data.length >= resJson.Total) {
									this.status = 'noMore'; // 没有更多数据
								} else {
									this.status = 'loading'; // 没有更多数据
								}
							} else {
								this.$errorToast(resJson.Msg);
								this.status = 'noMore'; // 没有更多数据
							}
						});
				} else if (key == 2) {
					SO_SOMainGetSa_SaleOrderAscendOut({
							PageIndex: this.pagination.current,
							PageRows: this.pagination.pageSize,
							Search: Search
						})
						.then(resJson => {
							if (resJson.Success) {
								this.Total = resJson.Total;
								this.data = resJson.Data;
								if (this.pagination.current == 1) {
									this.data = resJson.Data;
								} else {
									this.data = this.data.concat(resJson.Data);
								}
								if (this.data.length >= resJson.Total) {
									this.status = 'noMore'; // 没有更多数据
								} else {
									this.status = 'loading'; // 没有更多数据
								}
							} else {
								this.$errorToast(resJson.Msg);
								this.status = 'noMore'; // 没有更多数据
							}
						});
				} else if (key == 3) {
					SO_SOMainGetSa_SaleOrderAscendBill({
							PageIndex: this.pagination.current,
							PageRows: this.pagination.pageSize,
							Search: Search
						})
						.then(resJson => {
							if (resJson.Success) {
								this.Total = resJson.Total;
								this.data = resJson.Data;
								if (this.pagination.current == 1) {
									this.data = resJson.Data;
								} else {
									this.data = this.data.concat(resJson.Data);
								}
								if (this.data.length >= resJson.Total) {
									this.status = 'noMore'; // 没有更多数据
								} else {
									this.status = 'loading'; // 没有更多数据
								}
							} else {
								this.$errorToast(resJson.Msg);
								this.status = 'noMore'; // 没有更多数据
							}
						});
				} else if (key == 4) {
					SO_SOMainGetSA_ProcessGathering({
							PageIndex: this.pagination.current,
							PageRows: this.pagination.pageSize,
							Search: Search
						})
						.then(resJson => {
							if (resJson.Success) {
								this.Total = resJson.Total;
								this.data = resJson.Data;
								if (this.data.length >= resJson.Total) {
									this.status = 'noMore'; // 没有更多数据
								} else {
									this.status = 'loading'; // 没有更多数据
								}
							} else {
								this.$errorToast(resJson.Msg);
								this.status = 'noMore'; // 没有更多数据
							}
						});
				}

			},

			init() {
				// this.Id = "";
				// this.show = true;
				this.active = 0;
				// // this.data0 = [];
				// this.entity = {};
			},

			openForm(item) {
				this.init();
				if (item) {
					this.Id = item.ID;
					SO_SOMainGetTheData({
							Id: item.ID
						})
						.then(resJson => {
							this.entity = resJson.Data;
							if (this.entity.dDate) {
								this.entity.dDate = this.$moment(this.entity.dDate).format("YYYY-MM-DD")
							}
							// 获取详情--订单信息列表数据
							this.getTableData(this.active);
						});
				}
			}
		}
	};
</script>

<style scoped>
	.client {
		box-shadow: rgba(128, 128, 128, 0.1) 10px 10px 5px 5px;
	}

	.code {
		display: flex;
		justify-content: space-between;
		margin-left: 10px;
		margin-right: 10px;
		color: #777;
	}

	.rightFlax {
		margin-left: 10px;
	}

	.formalBox {
		padding-top: 20rpx;
		/* #ifdef H5 */
		height: calc(100vh - 340px);
		/* #endif */
		/* #ifdef APP */
		height: calc(100vh - 220px);
		/* #endif */
	}

	.companyName {
		font-size: 14px;
		padding-top: 10px;
		margin-left: 10px;
		margin-bottom: 5px;
		color: #000000;
		font-weight: 600;
		font-size: 18px;
		line-height: 1.8;
	}

	.boxFormal {
		box-shadow: 2px 2px 5px #ccc;
		border-radius: 5px;
		position: relative;
		background-color: #fff;
		width: 95%;
		/* height: 80px; */
		padding-bottom: 10px;
		margin: 3px auto;
		margin-bottom: 10px;
	}

	.tabsinfo>>>.van-tabs__content {
		height: calc(100% - 44px);
	}

	.van-tab__pane {
		height: 100%;
	}
</style>